<template>
  <view>
    <uni-popup ref="popup" type="dialog">
      <uni-popup-dialog type="warn" :confirmText="selectType == 1?'查看并签署《法定代表人全业务授权书》':'立即撤销'" title="恭喜！您已完成法定代表人身份认证！"
                        @confirm="dialogConfirm" @close="dialogClose">
        <template v-slot="content">
          <span>请完成以下操作：</span>
          <uni-data-checkbox v-model="selectType" :localdata="checkbox" style="margin: 16rpx 0 0 10rpx;"></uni-data-checkbox>
          <!-- 授权管理员全业务权限 -->
          <view v-if="selectType == 1">
            <view class="bg-color">
              <view>账户管理员：{{ adminInfo.adminName }}<br><span>实名手机号：{{ adminInfo.adminMobile }}</span></view>
              <view>账户授权状态：<span style="color:red">待法定代表人全业务授权</span></view>
            </view>
            <view class="line">通过法定代表人全业务授权后，管理员获得电子签约账户全部权限，是否立即授权？</view>
          </view>
          <!-- 撤销管理员全业务权限 -->
          <view v-if="selectType == 0">
            <view class="bg-color">
              <view>账户管理员：{{ adminInfo.adminName }}<br><span>实名手机号：{{ adminInfo.adminMobile }} </span></view>
              <view>账户授权状态：<span style="color:red">待撤销管理员全部管理权限</span></view>
            </view>
            <view class="line">撤销后，管理员失去电子签约账户全部管理权限，身份变为普通员工，是否立即撤销？</view>
          </view>
        </template>
      </uni-popup-dialog>
    </uni-popup>
  </view>
</template>

<script>
import {editAuthAdmin} from "../../api/ec/console/index";
import {changeCompany, changeUser} from "../../api/login";
import {updateSession} from "../../api/userInfo";

export default {
  data() {
    return {
      checkbox: [{
        text: '授权管理员全业务权限',
        value: 1
      }, {
        text: '撤销管理员全部管理权限 ',
        value: 0
      }],
      selectType: 1,
      adminInfo: {},//管理员信息
    }
  },
  methods: {
    openDialog(adminInfo) {
      this.adminInfo = adminInfo;
      this.$refs.popup.open('center')
    },
    dialogConfirm() {
      this.$modal.loading("加载中，请稍候...");
      editAuthAdmin({companyId: this.adminInfo.companyId, authAdminType: this.selectType}).then(response => {
        this.$modal.closeLoading();
        // 撤销管理员
        if (this.selectType == 0) {
          this.$modal.msgSuccess("撤销成功");
        }
        if (this.selectType== 1) {
          let data = response.data;
          // 签署全业务授权书
          changeUser(null).then(() => {
            updateSession().then((response) => {
              this.$store.dispatch('GetInfo').then((res) => {
                this.$tab.reLaunch(`/pages/sign/signedByme?id=${data.contractId}&flowId=${data.id}`)
              });
            });
          });
        }
      });
    },
    dialogClose() {
      this.$refs.popup.close();
    },
  }
}
</script>

<style lang="scss" scoped>
::v-deep .uni-dialog-title-text {
  font-size: 30rpx;
}

::v-deep .uni-data-checklist .checklist-group .checklist-box {
  margin: 16rpx 0;
}

.line {
  line-height: 46rpx;
}

::v-deep .uni-popup-dialog {
  width: 700rpx;
}

::v-deep .uni-dialog-button:first-child {
  display: none;
}

::v-deep .uni-dialog-button {
  background: $uni-color-primary;
}

::v-deep .uni-dialog-button-text {
  font-size: 30rpx;
  color: #fff;
}

::v-deep .uni-border-left {
  border: none;
}

.bg-color {
  color: #666;
  background-color: #f4f4f5;
  font-size: 26rpx;
  padding: 15rpx;
  line-height: 46rpx;
  margin: 18rpx 0;
}

::v-deep .uni-dialog-content {
  display: block;
}

</style>
